import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },



  {
    path: '/userlist',
    component: Layout,
    children: [
      {
        path: 'userlist',
        name: 'Form2',
        component: () => import('@/views/table/userlist'),
        meta: { title: '个人信息完善', icon: 'table' }
      }
    ]
  },
  // {
  //   path: '/workbench',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'workbench',
  //       name: 'Form3',
  //       component: () => import('@/views/table/process'),
  //       meta: { title: '工作台', icon: 'table' }
  //     }
  //   ]
  // },

  
  // // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

export const asyncRoutes = [
  

  {
    path: '/user',
    component: Layout,
    meta: { title: '用户管理', icon: 'el-icon-s-help',roles: ['系统管理员']},
    children: [
      {
        path: 'user',
        name: 'Form5',
        component: () => import('@/views/table/user'),
        meta: { title: '用户管理', icon: 'table',roles: ['系统管理员' ]}
      }
    ]
  },

  {
    path: '/chartView',
    component: Layout,
    meta: { title: '数据分析', icon: 'el-icon-s-help',roles: ['系统管理员']},
    children: [
      {
        path: 'chart',
        name: 'chart',
        component: () => import('@/views/chart/index'),
        meta: { title: '数据分析', icon: 'table',roles: ['系统管理员' ]}
      }
    ]
  },

  {
    path: '/DataLog',
    component: Layout,
    meta: { title: '操作日志', icon: 'el-icon-s-help',roles: ['系统管理员']},
    children: [
      {
        path: 'DataLogInfo',
        name: 'DataLogInfo',
        component: () => import('@/views/table/indexlist'),
        meta: { title: '操作日志', icon: 'table',roles: ['系统管理员' ]}
      }
    ]
  },



  {
    path: '/example',
    component: Layout,
    redirect: '/example/list',
    name: 'example',
    meta: {
      title: '档案管理',
      icon: 'el-icon-s-help',
      roles: ['系统管理员','档案管理员' ]
    },
    children: [
      {
        path: 'create',
        component: () => import('@/views/example/create'),
        name: 'CreateArticle',
        meta: { title: '上传档案', icon: 'edit' ,roles: ['系统管理员','档案管理员' ]}
      },
      {
        path: 'edit/:id(\\d+)',
        component: () => import('@/views/example/edit'),
        name: 'EditArticle',
        meta: { title: '编辑档案',  activeMenu: '/example/list',roles: ['系统管理员','档案管理员' ] },
        hidden: true
      },
      {
        path: 'list',
        component: () => import('@/views/example/list'),
        name: 'ArticleList',
        meta: { title: '档案列表', icon: 'list',roles: ['系统管理员','档案管理员' ] }
      }
    ]
  },


  {
    path: '/example1',
    component: Layout,
    redirect: '/example1/list',
    name: 'example1',
    meta: {
      title: '实体档案',
      icon: 'el-icon-s-help',
      roles: ['系统管理员','档案管理员' ]
    },
    children: [
      {
        path: 'create',
        component: () => import('@/views/example1/create'),
        name: 'CreateArticle1',
        meta: { title: '入库申请', icon: 'edit' ,roles: ['系统管理员','档案管理员' ]}
      },
      {
        path: 'edit/:id(\\d+)',
        component: () => import('@/views/example1/edit'),
        name: 'EditArticle1',
        meta: { title: '编辑档案',  activeMenu: '/example1/list',roles: ['系统管理员','档案管理员' ] },
        hidden: true
      },
      {
        path: 'list',
        component: () => import('@/views/example1/list'),
        name: 'ArticleList',
        meta: { title: '档案列表', icon: 'list',roles: ['系统管理员','档案管理员' ] }
      }
    ]
  },
  {
    path: '/documentlist',
    component: Layout,
    meta: { title: '档案列表', icon: 'table',roles: ['普通用户','档案管理员' ]},
    children: [
      {
        path: 'documentlist',
        name: 'Form3',
        component: () => import('@/views/table/documentlist'),
        meta: { title: '档案列表', icon: 'table',roles: ['普通用户','档案管理员' ]}
      }
    ]
  },

  {
    path: '/reduce',
    component: Layout,
    meta: { title: '回收站', icon: 'table',roles: ['系统管理员' ]},
    children: [
      {
        path: 'reduce',
        name: 'Reduce',
        component: () => import('@/views/table/reduce'),
        meta: { title: '回收站', icon: 'table',roles: ['系统管理员' ]}
      }
    ]
  },
  {
    path: '/storeroom',
    component: Layout,
    meta: { title: '库房管理', icon: 'table',roles: ['系统管理员' ]},
    children: [
      {
        path: 'storeroom',
        name: 'storeroom',
        component: () => import('@/views/table/storeroom'),
        meta: { title: '库房管理', icon: 'table',roles: ['系统管理员' ]}
      }
    ]
  },
  {
    path: '/process',
    component: Layout,
    meta: { title: '借阅管理', icon: 'table',roles: ['系统管理员','档案管理员' ]},
    children: [
      {
        path: 'process',
        name: 'Process',
        component: () => import('@/views/table/adminprocess'),
        meta: { title: '借阅管理', icon: 'table',roles: ['系统管理员' ]}
      }
    ]
  },
  {
    path: '/no',
    component: Layout,
    meta: { title: '公告', icon: 'table',roles: ['系统管理员' ,'普通用户']},
    children: [
      // {
      //   path: 'notice',
      //   name: 'Notice',
      //   component: () => import('@/views/table/notice'),
      //   meta: { title: '公告', icon: 'table',roles: ['系统管理员','档案管理员' ,'普通用户']}
      // },
      // {
      //   path: 'noticeDetail/:id(\\d+)',
      //   name: 'NoticeDetail',
      //   component: () => import('@/views/table/noticeDetail'),
      //   meta: { title: '公告详情', activeMenu: '/no/notice',icon: 'table',roles: ['系统管理员','档案管理员','普通用户' ]},
      //   hidden: true
      // },
      {
        path: 'editnotice',
        name: 'Editnotice',
        component: () => import('@/views/table/editnotice'),
        meta: { title: '发布公告', icon: 'table',roles: ['系统管理员','档案管理员' ]}
      },
      {
        path: 'enotice/:id(\\d+)',
        name: 'Enotice',
        component: () => import('@/views/table/enotice'),
        meta: { title: '编辑公告', icon: 'table',roles: ['系统管理员','档案管理员' ]},
        hidden: true
      },
      {
        path: 'noticelist',
        name: 'Noticelist',
        component: () => import('@/views/table/noticelist'),
        meta: { title: '公告列表', activeMenu: '/no/notice',icon: 'table',roles: ['系统管理员']}
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
